import java.io.*;

/*
ID: qingtia2
LANG: JAVA
TASK: ride
*/
class ride {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new FileReader("ride.in"));
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("ride.out")));
        String s1 = in.readLine();
        String s2 = in.readLine();
        char[] chars1 = s1.toCharArray();
        long j1 = 1;
        for (char c : chars1) j1 = j1 * (c - 'A' + 1) % 47;
        char[] chars2 = s2.toCharArray();
        long j2 = 1;
        for (char c : chars2) j2 = j2 * (c - 'A' + 1) % 47;
        out.println(j1 == j2 ? "GO" : "STAY");
        out.close();
    }
}
